<template>
	<view>
		<!-- 公建进度，房屋进度 -->
		<TopNavCustom :title="title"></TopNavCustom>
		<view class="container">
			<question-echart :all="sumList.totalCount" :wip="sumList.notPassCount" :ip='sumList.passCount'
				:nodeList='sumList.nodeList'>
			</question-echart>
			<view class="tab-content">
				<u-subsection :list="list" mode="subsection" :current="current" activeColor="transparent"
					@change="change" fontSize='30rpx'>
				</u-subsection>
				<!-- 上传列表 -->
				<view v-if="current ===0">
					<view v-for="(item,index) in progressList" :key="index">
						<view class="item" @click="gotoDetail(item)">
							<image :src="getSrc(item.issueImages)" class="pix"></image>
							<view class="right">
								<view class="top">
									<view style="display: inline-flex; align-items: center;">
										<text class="p-name">{{item.faultName}}</text>
										<text class="tag">{{TAG}}</text>
									</view>
								</view>
								<text>{{item.discoveryTime}}</text>
								<button type="default" class="btn">上传</button>
							</view>
						</view>
					</view>
					<!-- 为空数据时候 -->
					<u-empty v-if="progressList.length==0" text="暂无记录~" icon="/static/home_icons/nodata.png"
						marginTop="166rpx" width="200rpx" height="131rpx">
					</u-empty>
				</view>
				<view v-if="current==1">
					<view v-for="(item,index) in progressListChecked" :key="index">
						<view class="item" @click.stop="gotoDetail(item)">
							<image :src="getSrc(item.issueImages)" class="pix"></image>
							<view class="right">
								<view class="top">
									<view style="display: inline-flex; align-items: center;">
										<text class="p-name">{{item.faultName}}</text>
										<text class="tag">{{TAG}}</text>
									</view>
									<text
										:class="(item.issuesStatus===2 || item.issuesStatus===11)? 'check-status':'check-status-fail'">{{getStatus(item.issuesStatus)}}</text>
								</view>
								<text>{{item.discoveryTime}}</text>
								<button type="default" class="btn"
									v-if="item.issuesStatus===4">{{getStatus(item.issuesStatus)}}</button>
							</view>
						</view>
					</view>
					<!-- 为空数据时候 -->
					<u-empty v-if="progressListChecked.length==0" text="暂无记录~" icon="/static/home_icons/nodata.png"
						marginTop="166rpx" width="200rpx" height="131rpx">
					</u-empty>
				</view>
				<view v-if="current===2">
					<view v-for="(item,index) in progressListUpload" :key="index">
						<view class="item" @click="gotoDetail(item)">
							<image :src="getSrc(item.issueImages)" class="pix"></image>
							<view class="right">
								<view class="top">
									<view style="display: inline-flex; align-items: center;">
										<text class="p-name">{{item.faultName}}</text>
										<text class="tag">{{TAG}}</text>
									</view>
								</view>
								<text>{{item.discoveryTime}}</text>
								<button type="default" class="btn" v-if="item.issuesStatus===3">删除</button>
							</view>
						</view>
					</view>
					<!-- 为空数据时候 -->
					<u-empty v-if="progressListUpload.length==0" text="暂无记录~" icon="/static/home_icons/nodata.png"
						marginTop="166rpx" width="200rpx" height="131rpx">
					</u-empty>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import _question from "@/common/question.js"
	import $C from '@/common/config.js'

	export default {
		onLoad(params) {
			let _item = JSON.parse(decodeURIComponent(params.item))
			this.partName = _item.partName
			this.flag = _item._title
			this.estateId = _item.estateId
			if (_item._title == '项目安全') {
				this.title = _item.partName + _item._title
				this.partId = _item.partId
			} else {
				this.title = _item.building + "栋" + _item.unit + "单元" + _item.num + "号" + "安全";
				this.rootPartId = '1'
			}
			this.TAG = uni.getStorageSync('selectedProject')

			this.getProgressListUnupload()
			this.getProgressListChecked()
			this.getProgressListUpload()
			this.getSum()
		},
		methods: {
			async getProgressListUnupload() {
				let _push_form = {}
				if (this.flag == '项目安全') {
					_push_form.partId = this.partId
				} else {
					_push_form.rootPartId = '1'
				}
				_push_form.estateId = this.estateId
				_push_form.statusList = [1]
				_push_form.issuesType = 2
				this.progressList = await _question.getQuestionList(_push_form)
			},
			gotoDetail(item) {
				let status = item.issuesStatus
				let nextUrl = ''
				switch (status) {
					case 1:
						nextUrl = '/pages/idata/safe/upload_safe/upload_safe?item='
						break;
					case 2:
						nextUrl = '/pages/idata/safe/check_details/check_details?item='
						break;
					case 11:
						nextUrl = '/pages/idata/safe/check_details/check_details?item='
						break;
					case 3:
						nextUrl = '/pages/idata/safe/check_details/check_details?item='
						break;
					case 4:
						nextUrl = '/pages/idata/safe/check_details/check_details?item='
						break;
				}
				let temp = item
				temp.title = this.title
				temp.partId = this.partId
				temp.estateId = this.estateId
				console.log(temp.partId)
				let node = encodeURIComponent(JSON.stringify(temp))
				uni.navigateTo({
					url: nextUrl + node
				})
			},
			getSrc(ids) {
				if (ids == null || typeof ids == undefined)
					return
				let idArray = ids.split(',')
				let id = idArray[0]
				if ((typeof id) != undefined && id != '') {
					let _src = $C.baseUrl + '/file/download?fileId=' + id
					return _src
				}
			},
			getStatus(status) {
				switch (status) {
					case 1:
						return '待上传'
						break;
					case 2:
						return '待审核'
						break;
					case 11:
						return '已上传'
						break;
					case 3:
						return '已通过'
						break;
					case 4:
						return '重新审核'
						break;
				}
			},
			async getSum() {
				let _push_form = {}
				_push_form.estateId = this.estateId
				if (this.flag == '项目安全') {
					_push_form.partId = this.partId
				} else {
					_push_form.rootPartId = '1'
				}
				_push_form.issuesType = 2
				this.sumList = await _question.getQuestionEchart(_push_form)
			},
			async getProgressListChecked() {
				let _push_form = {}
				if (this.flag == '项目安全') {
					_push_form.partId = this.partId
				} else {
					_push_form.rootPartId = '1'
				}
				_push_form.estateId = this.estateId
				_push_form.statusList = [2, 11, 4]
				_push_form.issuesType = 2
				this.progressListChecked = await _question.getQuestionList(_push_form)
			},
			async getProgressListUpload() {
				let _push_form = {}
				if (this.flag == '项目安全') {
					_push_form.partId = this.partId
				} else {
					_push_form.rootPartId = '1'
				}
				_push_form.estateId = this.estateId
				_push_form.statusList = [3]
				_push_form.issuesType = 2
				this.progressListUpload = await _question.getQuestionList(_push_form)
			},
			change(index) {
				this.current = index
				switch (index) {
					case 0:
						this.getProgressListUnupload()

						break;
					case 1:
						this.getProgressListChecked()
						break;
					case 2:
						this.getProgressListUpload()
						break;
				}
			},
		},
		data() {
			return {
				flag: '',
				time: uni.$u.timeFormat(false, 'yyyy-mm-dd'),
				title: '',
				current: 0,
				checkStatus: '审核中',
				list: [{
					name: '待上传',
				}, {
					name: '待审核',
				}, {
					name: '已通过'
				}],
				progressList: [],
				partId: '',
				estateId: '',
				rootPartId: '',
				partName: '',
				sumList: {},
				progressListChecked: [],
				progressListUpload: [],
				TAG: ''
			};
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		padding: 20rpx 30rpx;

		.tab-content {
			background-color: #FFFFFF;
			margin-top: 20rpx;
			border-radius: 20rpx;
			border: 1rpx solid #efefef;
			padding: 30rpx;
			display: flex;
			flex-direction: column;

			.upload-list {
				display: flex;
				flex-direction: column;
			}
		}
	}

	.item {
		display: flex;
		flex-direction: row;
		width: 100%;
		margin-top: 40rpx;

		.pix {
			width: 180rpx;
			height: 180rpx;
			border-radius: 10rpx;
		}

		.right {
			width: 425rpx;
			margin-left: 25rpx;
			display: flex;
			flex-direction: column;

			.top {
				width: 100%;
				display: flex;
				flex-direction: row;
				align-items: center;
				font-size: 30rpx;
				font-weight: bold;
				color: #333333;
				line-height: 54rpx;
				justify-content: space-between;

				.tag {
					line-height: 30rpx;
					margin-left: 5rpx;
					height: 30rpx;
					background: linear-gradient(0deg, #E93423 0%, #FB6858 100%);
					border-radius: 6rpx;
					text-align: center;
					font-size: 10rpx;
					color: #FFFFFF;
					width: 80rpx;
					overflow: hidden;
					/* #ifndef APP-NVUE */
					white-space: nowrap;
					text-overflow: ellipsis;
					/* #endif */
					/* #ifdef APP-NVUE */
					lines: 1;
					text-overflow: ellipsis;
					/* #endif */
				}

			}

			.check-status {
				margin-left: 100rpx;
				color: orange;
			}

			.check-status-fail {
				margin-left: 100rpx;
				color: red;
			}

			.btn {
				color: #FFFFFF;
				margin-left: 265rpx;
				font-size: 24rpx;
				height: 56rpx;
				width: 160rpx;
				border-radius: 28rpx;
				background: linear-gradient(0deg, #E93423 0%, #FB6858 100%);
			}
		}
	}

	.container /deep/ .u-subsection--subsection {
		height: 80rpx;
		background: #EBEBEB;
		border-radius: 40rpx;
		border: 1rpx solid #F5FFF0 !important;
	}

	.container /deep/ .u-subsection__bar {
		height: 80rpx;
		background: linear-gradient(0deg, #E93423 0%, #FB6858 100%);
		border-radius: 40rpx;
	}

	.p-name {
		font-size: 28rpx;
		width: 100rpx;
		overflow: hidden;
		/* #ifndef APP-NVUE */
		white-space: nowrap;
		text-overflow: ellipsis;
		/* #endif */
		/* #ifdef APP-NVUE */
		lines: 1;
		text-overflow: ellipsis;
		/* #endif */
	}
</style>
